#include "stdafx.h"
#include "SOCK_Connector.h"
#include <iostream>

using namespace std;
#pragma comment(lib,"ws2_32.lib") //Winsock Library

SOCK_Connector::SOCK_Connector(void)
{	
	WSADATA wsa;

	WSAStartup(MAKEWORD(2,2), &wsa);
}

SOCK_Connector::~SOCK_Connector(void)
{
	closesocket(sockfd);
}

int SOCK_Connector::connect(INET_Addr& address,SOCK_Stream &s)
{
	sockfd = socket(AF_INET, SOCK_STREAM, 0);

	::ioctlsocket(sockfd, FIONBIO, (u_long*)1);

	if(INVALID_SOCKET == sockfd)
		cout << "Invalid socket" << endl;
	s.set_handle(sockfd);

	//int result = ::connect(sockfd, address.addr(), address.size());
	//int result2 = ::send(sockfd, "hej med dig,5",13,0);

	//if(result < 1)
	//	result = WSAGetLastError();

	return ::connect(sockfd, address.addr(), address.size());
}